﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SN.Models;
using SN.Data;
namespace SN.Report
{
    public partial class FormAttribute : Form
    {
        private r_Report report;

        public r_Report Report
        {
            get { return report; }
            set { report = value; }
        }

        public FormAttribute()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //保存报表属性
            report.Report_IndexCol = txtIndex.Text.Trim();
            report.Reprot_DimensionRow = txtDemin.Text.Trim();
            report.Report_ClassId = int.Parse(txtClassId.Text.Trim()); //报表类别
            report.Report_Cycle = combox1.Text.Trim();
            report.Report_Sfmb = Convert.ToInt16(checkBox1.Checked); //是否使用模板 
            SN.Data.DBUtility.DB.Update<r_Report>(new Field[] { r_Report._.Report_IndexCol, 
                                                                r_Report._.Reprot_DimensionRow, 
                                                                r_Report._.Report_Cycle, 
                                                                r_Report._.Report_ClassId,
                                                                r_Report._.Report_Sfmb},
                                                  new object[] { Report.Report_IndexCol, 
                                                                 Report.Reprot_DimensionRow,
                                                                 Report.Report_Cycle,
                                                                 Report.Report_ClassId,
                                                                 Report.Report_Sfmb},
                                                  r_Report._.Report_Id == Report.Report_Id);

            //
            DialogResult = DialogResult.OK;
            Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void FormAttribute_Load(object sender, EventArgs e)
        {
            txtIndex.Text = Report.Report_IndexCol;
            txtDemin.Text = Report.Reprot_DimensionRow; //
            combox1.Text = report.Report_Cycle;//报表周期
            txtClassId.Text = report.Report_ClassId.ToString(); //报表类别
            checkBox1.Checked = Convert.ToBoolean(report.Report_Sfmb); //是否使用模板  0 不使用 1 使用
            txtClassName.Text = SN.Data.DBUtility.DB.Field<r_ReportClass>(r_ReportClass._.Class_Name, r_ReportClass._.Class_Id == report.Report_ClassId).ToString();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            FormChooseClass frm = new FormChooseClass();
            if (frm.ShowDialog() == DialogResult.OK)
            {
                this.txtClassId.Text = frm.Classes.Class_Id.ToString();
            }
            else
            {
                return;
            }
        }
    }
}

